home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Franz PD / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).zip / Franz PD Disk #002 (19xx)(Amiga User Group Deutschland e.V.).adf / 3-D_Stars / 3dstars.c < prev    next >
C/C++ Source or Header  |  1986-10-22  |  3KB  |  149 lines

  1. /*  :ts=8 bk=0
  2.  * 3dstars.c:  Spacing out taken a step further
  3.  * by Leo L. Schwab   8607.1
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/intuition.h>
  8.  
  9. #define NSTARS        32
  10.  
  11. extern void *OpenLibrary(), *OpenScreen(), *OpenWindow(), *GetMsg();
  12. extern short rnd();
  13.  
  14. long *IntuitionBase, *GfxBase;
  15.  
  16. struct NewScreen scrdef = {
  17.     0, 0, 320, 200,
  18.     4,        /*  # planes  */
  19.     -1, -1,
  20.     NULL,
  21.     CUSTOMSCREEN,
  22.     NULL, NULL, NULL, NULL
  23. };
  24.  
  25. struct NewWindow windef = {
  26.     0, 0, 320, 200,
  27.     -1, -1,
  28.     CLOSEWINDOW,
  29.     WINDOWCLOSE,
  30.     NULL, NULL, NULL, NULL, NULL,
  31.     0, 0, 0, 0,
  32.     CUSTOMSCREEN
  33. };
  34.  
  35. struct Window *win;
  36. struct Screen *scr;
  37. struct RastPort *rp;
  38. short x[NSTARS], y[NSTARS], z[NSTARS];
  39. short xlo[NSTARS], xro[NSTARS], yo[NSTARS];
  40.  
  41.  
  42. main (ac, av)
  43. char *av[];
  44. int ac;
  45. {
  46.     long xls, xrs, ys;
  47.     long *msg;
  48.     short magic, inc;
  49.     register short i, fz;
  50.  
  51.     if (ac > 1)
  52.         magic = atoi (av[1]);
  53.     else
  54.         magic = 128;
  55.  
  56.     if (ac > 2)
  57.         inc = atoi (av[2]);
  58.     else
  59.         inc = 3;
  60.  
  61.     openstuff ();
  62.     rnd (-5286);
  63.     SetRast (rp, 0L);
  64.     for (i=0, xls=1; i<8; i++, xls += 2) {
  65.         SetRGB4 (&(scr -> ViewPort), (long) i, xls, 0L, 0L);
  66.         SetRGB4 (&(scr -> ViewPort), (long) i+8, 0L, 0L, xls);
  67.     }
  68.  
  69.     for (i=0; i<NSTARS; i++)
  70.         mkpoint (i);
  71.  
  72.     FOREVER {
  73.         for (i=0; i<NSTARS; i++) {
  74.             if ((z[i] -= inc) <= 0)
  75.                 mkpoint (i);
  76.             fz = z[i];
  77.             xls = (x[i] - (fz >> 4)) * magic / fz + 160;
  78.             xrs = (x[i] + (fz >> 4)) * magic / fz + 160;
  79.             ys = y[i] * magic / fz + 100;
  80.             SetAPen (rp, 0L);
  81.             WritePixel (rp, (long) xlo[i], (long) yo[i]);
  82.             WritePixel (rp, (long) xro[i], (long) yo[i]);
  83.             if (xls < 0 || xls > 319 || xrs < 0 || xrs > 319 ||
  84.                 ys < 0 || ys > 199)
  85.                 mkpoint (i);
  86.             else {
  87.                 SetAPen (rp, (long) (256-fz >> 5));
  88.                 WritePixel (rp, xls, ys);
  89.                 SetAPen (rp, (long) 8+(256-fz >> 5));
  90.                 WritePixel (rp, xrs, ys);
  91.                 xlo[i] = xls;  xro[i] = xrs;  yo[i] = ys;
  92.             }
  93.         }
  94.         if (msg = GetMsg (win -> UserPort)) {
  95.             ReplyMsg (msg);
  96.             break;
  97.         }
  98.     }
  99.  
  100.     closestuff ();
  101. }
  102.  
  103. mkpoint (i)
  104. register short i;
  105. {
  106.     x[i] = rnd (256) - 128;
  107.     y[i] = rnd (150) - 75;
  108.     z[i] = 255;
  109. }
  110.  
  111. openstuff ()
  112. {
  113.     if (!(IntuitionBase = OpenLibrary ("intuition.library", 0L))) {
  114.         printf ("Intuition open failed.\n");
  115.         die ();
  116.     }
  117.  
  118.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L))) {
  119.         printf ("graphics open failed.\n");
  120.         die ();
  121.     }
  122.  
  123.     if (!(scr = OpenScreen (&scrdef))) {
  124.         printf ("Can't open screen.\n");
  125.         die ();
  126.     }
  127.  
  128.     windef.Screen = scr;
  129.     if (!(win = OpenWindow (&windef))) {
  130.         printf ("Window painted shut.\n");
  131.         die ();
  132.     }
  133.     rp = &(scr -> RastPort);
  134. }
  135.  
  136. closestuff ()
  137. {
  138.     if (win)        CloseWindow  (win);
  139.     if (scr)        CloseScreen  (scr);
  140.     if (GfxBase)        CloseLibrary (GfxBase);
  141.     if (IntuitionBase)    CloseLibrary (IntuitionBase);
  142. }
  143.  
  144. die ()
  145. {
  146.     closestuff ();
  147.     exit (-1);
  148. }
  149.